package com.doublefish.doublefishrobot.ui.home.path.tools;

import com.doublefish.doublefishrobot.ui.home.bean.ModeSettingBean;
import com.doublefish.doublefishrobot.ui.home.path.bean.BallParamsBean;

/**
 * 作者:dugaofeng on 2025/4/11 15:00
 */
public class S5ParamTranslateUtils {

    public static BallParamsBean s5ParamTranslate(ModeSettingBean.ModeSettingStepBean stepBean) {
        int speed = stepBean.getSpeedItemBean().getCurrentValue();
        int landPoint = stepBean.getHorizontalItemBean().getCurrentValue();

        int rotation = 0;   //0.不旋  1上旋  2下旋
        if (stepBean.getRotationType() == 1) {
            rotation = stepBean.getUpRotationItemBean().getCurrentValue();
        } else if (stepBean.getRotationType() == 2) {
            rotation = -stepBean.getDownRotationItemBean().getCurrentValue();
        }

        return s5ParamTranslate(speed, landPoint, rotation);
    }



    private static BallParamsBean s5ParamTranslate(int speed, int landPoint, int rotation) {
        BallParamsBean bean = new BallParamsBean();
        bean.setHeight(0.28f);   //默认0.28m

        //速度转化
        //此处的速度是小杰测试出的结果，单位为km/h 对一个发球机的1-9档
        float spds[] = {17.794f, 23.62f, 29.474f, 34.534f, 40.9f, 45.578f, 51.164f, 56.204f, 61.738f};
        //转化为 m/s
        if (speed < 1) {
            speed = 1;
        } else if (speed > 9) {
            speed = 9;
        }
        //todo 旧的发球轮 速度变慢  先减去1.5
        bean.setSpeed((spds[speed - 1] - 1.5f) / 3.6f);


        //上下旋 正负
        int sign = 1;
        if (rotation < 0) {
            sign = -1;
            rotation = -rotation;  //先把负数 转为正数进行判断
        }
        //上下旋 是非线性的 需要调整
        //0-5 是正常发球
        //6档以上发球机会搓球，导致出现较大误差
        //大于5 都按5算
        if (rotation >= 5) {
            rotation = 5;
        }
        //重新赋予正负号
        rotation *= sign;
        //根据测试：5档强度 大约在3~4之间，取平均值3.5
        bean.setRotation(rotation * 3.5f / 5);

        //落点  -23 ~ 23   对应发球机 1 ~ 11,中点为6   倍数： 5/23
        bean.setLandPoint((landPoint - 6) * 23.0f / 5);

        //仰角 由用户自行调整， 此处默认2
        bean.setElevation(2);
        //侧旋
        bean.setSideSpin(0);

        return bean;
    }
}

